from crcmod import crcmod


def beacon_sn_decode(sn):
    result = ((int(sn) & 0x0000ffff) ^ 0x3221).to_bytes(2, byteorder="big")
    data = b"\x11" + result + b"\x20"
    crc16 = crcmod.predefined.Crc('xmodem')
    crc16.update(data)
    crc = crc16.crcValue
    data = data + (crc & 0x00ff).to_bytes(1, byteorder="big") + (crc >> 8).to_bytes(1, byteorder="big")
    print(data.hex().upper())



if __name__ == "__main__":
    beacon_sn_decode(6640)
    beacon_sn_decode(6637)
    beacon_sn_decode(8577)


